package org.ehe.finance.receipt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.ehe.common.mybatis.core.mapper.BaseMapperPlus;
import org.ehe.finance.receipt.domain.ErpFinanceReceipt;
import org.ehe.finance.receipt.domain.bo.ReceiptBo;
import org.ehe.finance.receipt.domain.vo.ReceiptResponseVO;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author :zhangnn
 * @className :ReceiptMapper
 * @description: TODO
 * @date 2025-09-02 14:24:50
 */
@Mapper
public interface ReceiptMapper extends BaseMapper<ErpFinanceReceipt> {
    /**
     * 分页查询收款单
     * @param page 分页对象
     * @param queryVO 查询条件
     * @return 收款单列表
     */
    Page<ReceiptResponseVO> selectReceiptPage(Page<ReceiptResponseVO> page, @Param("query") ReceiptBo queryVO);

    /**
     * 查询收款单详情
     * @param id 收款单ID
     * @return 收款单详情
     */
    ReceiptResponseVO selectReceiptDetail(@Param("id") Long id);

    /**
     * 查询即将到期收款
     * @param days 天数
     * @return 即将到期收款列表
     */
    List<ErpFinanceReceipt> selectDueReceipts(@Param("days") int days);

    /**
     * 客户收款统计
     * @return 统计结果
     */
    List<ReceiptStatistics> selectReceiptStatisticsByCustomer();

    /**
     * 检查收款单号是否存在
     * @param receiptNo 收款单号
     * @param id 排除的ID
     * @return 存在数量
     */
    int checkReceiptNoExists(@Param("receiptNo") String receiptNo, @Param("id") Long id);

    /**
     * 收款统计内部类
     */
    class ReceiptStatistics {
        private Long customerId;
        private String customerName;
        private BigDecimal totalAmount;
        private Integer receiptCount;

        // getters and setters
        public Long getCustomerId() {
            return customerId;
        }

        public void setCustomerId(Long customerId) {
            this.customerId = customerId;
        }

        public String getCustomerName() {
            return customerName;
        }

        public void setCustomerName(String customerName) {
            this.customerName = customerName;
        }

        public BigDecimal getTotalAmount() {
            return totalAmount;
        }

        public void setTotalAmount(BigDecimal totalAmount) {
            this.totalAmount = totalAmount;
        }

        public Integer getReceiptCount() {
            return receiptCount;
        }

        public void setReceiptCount(Integer receiptCount) {
            this.receiptCount = receiptCount;
        }
    }
}
